<script type="text/javascript" src="<?php echo base_url() . SKINSPATH; ?>js/jquery.timepicker/jquery-ui-timepicker-addon.js"></script>
<link rel="stylesheet" href="<?php echo base_url() . SKINSPATH; ?>js/jquery.timepicker/jquery-ui-timepicker-addon.css" type="text/css"/>
<div class="content-box">
    <div class="box-header clear">
        <h2><?php echo lang('pg_add_contract') ?></h2>
    </div>
    <div class="box-body clear">
        <?php echo validation_errors('<li class="error">', '</li>'); ?>
        <?php echo form_open(base_url() . 'contract/add/'.$id); ?>
        <div class="form-field clear">
            <label class="form-label fl-space2"><?php echo lang('lbl_contract_name') ?> :(<span class="required">*</span>)</label>
            <input type="text" value="<?php echo set_value('contract_name'); ?>" name="contract_name" class="text" maxlength="80" />
        </div>
        <div class="form-field clear">
            <label class="form-label fl-space2"><?php echo lang('lbl_contract_number') ?> :(<span class="required">*</span>)</label>
            <input type="text" value="<?php echo set_value('contract_number'); ?>" name="contract_number" class="text" maxlength="50" />
        </div>
        <div class="form-field clear">
            <label class="form-label fl-space2"><?php echo lang('lbl_category') ?> :</label>
            <select name="category_id" id="category_id" onchange="getProduct();">
            	<option value=""><?php echo lang('lbl_select_category') ?></option>
            <?php 
            foreach($categorys as $item){
				echo "<option value='".$item->id."'>".$item->category_name."</option>";
			}
            ?>
            </select>
        </div>
        <div class="form-field clear">
            <label class="form-label fl-space2"><?php echo lang('lbl_provider') ?> :</label>
            <select name="provider_id" id="provider_id" onchange="getProduct();">
            	<option value=""><?php echo lang('lbl_select_provider') ?></option>
            <?php 
            foreach($providers as $item){
				echo "<option value='".$item->id."'>".$item->provider_name."</option>";
			}
            ?>
            </select>
        </div>
        <div class="form-field clear">
            <label class="form-label fl-space2"><?php echo lang('lbl_product') ?> :</label>
            <select name="product_id" id="product_id">
            	<option value=""><?php echo lang('lbl_select_product') ?></option>
            </select>
        </div>
        <div class="form-field clear">
            <label class="form-label fl-space2"><?php echo lang('lbl_start_date') ?> :</label>
            <input type="text" value="<?php echo set_value('start_date'); ?>" name="start_date" id="start_date" class="text" maxlength="10" />
        </div>
        <div class="form-field clear">
            <label class="form-label fl-space2"><?php echo lang('lbl_end_date') ?> :</label>
            <input type="text" value="<?php echo set_value('end_date'); ?>" name="end_date" id="end_date" class="text" maxlength="10" />
        </div>
        <div class="form-field clear">
                <label class="form-label fl-space2"><?php echo lang('lbl_termination_alert') ?> </label>
                <input type="radio" value="0" name="termination_alert" checked="true" /> <?php echo lang('lbl_off');?>
                <input type="radio" value="1" name="termination_alert" /> <?php echo lang('lbl_on');?>
            </div>
        <div class="form-field clear">
            <label class="form-label fl-space2"><?php echo lang('lbl_termination_date') ?> :</label>
            <?php echo form_dropdown('termination_date', $termination_date); ?>
        </div>
        <div class="form-field clear">
            <label class="form-label fl-space2"><?php echo lang('lbl_status') ?> :</label>
            <?php echo form_dropdown('status', $status); ?>
        </div>
        <div class="form_submit">
            <input type="submit" class="submit" value="<?php echo lang('btn_save') ?>" id="save" name="save">
            <input onclick='location.href = "<?php echo base_url(); ?>contract/<?php echo $id;?>"' type="button" class="submit" value="<?php echo lang('btn_cancel') ?>" name="cancel">
        </div>
        <?php echo form_close(); ?>
    </div>
</div>
<script type="text/javascript">
    $('#start_date').datetimepicker({
        dateFormat: "yy/mm/dd"
    });
    $('#end_date').datetimepicker({
        dateFormat: "yy/mm/dd"
    });
    function getProduct(){
		if($('#category_id').val() && $('#provider_id').val()){
			$.ajax({
	            type: "POST",
	            url: "<?php echo base_url() ?>contract/getproduct",
	            data: "category_id=" + $('#category_id').val() + "&provider_id=" + $('#provider_id').val(),
	            success: function(result) {
	            	$('#product_id').html( result );
	            }
	        })
		}
    }
</script>